#include "world.h"
#include <vector>
World::World(int width, int height, int unit) : renderer(nullptr), width(width), height(height), unit(unit)
{
	box.w = unit - lineWidth - 2 * padding;
	box.h = box.w;
	hor_line.w = width*unit;
	ver_line.h = height*unit;
	for (int i = 0; i < height; ++i)
	{
		Bitmap row(width);
		blocks[0].push_back(row);
	}
	for (int i = 0; i < height; ++i)
	{
		Bitmap row(width);
		blocks[1].push_back(row);
	}
}

void World::drawBlock(int x, int y)
{
	box.x = lineWidth + padding + x * unit;
	box.y = lineWidth + padding + y * unit;
	SDL_RenderFillRect(renderer, &box);
}

void World::draw()
{
	int row_idx = 0;

	SDL_SetRenderDrawColor(renderer, 128, 128, 128, 0);
	for (int i = 0; i < height; ++i)
	{
		hor_line.y = i * 20;
		SDL_RenderDrawRect(renderer, &hor_line);

	}
	for (int i = 0; i < width; ++i)
	{
		ver_line.x = i * 20;
		SDL_RenderDrawRect(renderer, &ver_line);
	}
	SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);

	for (Bitmap& row : blocks[currBlocks])
	{
		for (int i = 0; i < width; ++i)
		{
			if (row[i])
			{
				drawBlock(i, row_idx);
			}
		}
		++row_idx;
	}
}